package com.sh.创建方法;


import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class ThreadExperiment {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        ThreadOne thread1 = new ThreadOne();
//        ThreadOne thread2 = new ThreadOne();
//        thread1.setName("线程1");
//        thread2.setName("线程2");
//        thread1.start();
//        thread2.start();


//        RunnableOne runnable = new RunnableOne();
//        Thread thread1 = new Thread(runnable);
//        Thread thread2 = new Thread(runnable);
//        thread1.setName("线程1");
//        thread2.setName("线程2");
//        thread1.start();
//        thread2.start();


        CallableOne callable = new CallableOne();
        FutureTask<String> futureTask1 = new FutureTask<>(callable);
        FutureTask<String> futureTask2 = new FutureTask<>(callable);
        Thread thread1 = new Thread(futureTask1);
        Thread thread2 = new Thread(futureTask2);
        thread1.setName("线程1");
        thread2.setName("线程2");
        thread1.start();
        thread2.start();
//        thread1.sleep(1000);
        String s1 = futureTask1.get();
        String s2 = futureTask1.get();
        System.out.println("线程1执行的结果是: " + s1);
        System.out.println("线程2执行的结果是: " + s2);
    }
}